package com.xadmin.sys.rbac.controller;


import com.xadmin.sys.common.response.Result;
import com.xadmin.sys.rbac.mapper.NoticeMapper;
import com.xadmin.sys.rbac.mapper.UserMapper;
import com.xadmin.sys.rbac.pojo.Notice;
import com.xadmin.sys.rbac.service.NoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 公告
 */
@RestController
@RequestMapping("/notice")
@Api(value = "系统首页模块",tags = "系统首页模块")
public class NoticeController {
    @Resource
    private NoticeService noticeService;
    @Resource
    private NoticeMapper noticeMapper;
    @Resource
    private UserMapper userMapper;

    @RequestMapping(value = "/addNotice",method = RequestMethod.POST)
    @ApiOperation(value = "发布公告",notes = "发布公告")
    public Result addNotice(@RequestBody Notice notice){
        boolean  check =noticeService.save(notice);
        if(check){
            return  Result.ok().message("添加成功！");
        }else {
            return Result.error().message("用户已存在！");
        }
    }

    @RequestMapping(value = "/getNotice",method = RequestMethod.GET)
    @ApiOperation(value = "获取最新公告",notes = "获取最新公告")
    public Result getNotice(){
        Notice notice = noticeMapper.getNotice();
        return  Result.ok().data("data",notice);
    }

    @RequestMapping(value = "/getCount",method = RequestMethod.GET)
    @ApiOperation(value = "首页统计数量",notes = "首页统计数量")
    public Result getCount(){
        int noticeCount = noticeMapper.getCount();
        int userCount = userMapper.getCount();
        List<Integer> list = new ArrayList();
        list.add(noticeCount);
        list.add(userCount);
        return  Result.ok().data("data",list);
    }
}

